package com.glory.cqaospda.view

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.text.Editable
import android.text.TextWatcher
import android.view.KeyEvent
import android.view.View
import android.widget.EditText
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.glory.cqaospda.R
import com.glory.cqaospda.adapter.MateriaAdapter
import com.glory.cqaospda.base.Constant
import com.glory.cqaospda.base.MyApp
import com.glory.cqaospda.bean.BaseConfigBean
import com.glory.cqaospda.bean.CheckBoxList
import com.glory.cqaospda.bean.EqpMaterialsBean
import com.glory.cqaospda.bean.EqpMaterialsBean.Materialslist
import com.glory.cqaospda.bean.MaterialListBean
import com.glory.cqaospda.utils.EditTextEnterUtils
import com.glory.cqaospda.viewmodel.MaterialReplaceModel
import com.glory.mvvmnet.base.BaseActivity
import com.glory.mvvmnet.entity.ToastMessageBean
import com.glorysoft.hlgdpda.utils.PopWindowsUtils
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ActivityManager
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_EditTextUtils
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText
import kotlinx.android.synthetic.main.activity_material_replace.*
import kotlinx.android.synthetic.main.activity_title.*
import kotlinx.android.synthetic.main.carriertape_layout.*
import kotlinx.android.synthetic.main.cover_layout.*
import kotlinx.android.synthetic.main.plug_layout.*
import kotlinx.android.synthetic.main.reel_layout.*
import java.lang.Exception

class QueryMaterialReplaceActivity : BaseActivity<MaterialReplaceModel>(), View.OnClickListener {

    var typeActivity = ""
    var eqpid = ""
    var BuyOff = "1"
    var temperature = ""
    private var codePop: PopWindowsUtils.GeneralPop? = null
    var list: ArrayList<String> = ArrayList()
    var checkBoxList = ArrayList<CheckBoxList>()
    var checkBoxListBean1 = CheckBoxList()
    var checkBoxListBean2 = CheckBoxList()
    var checkBoxListBean3 = CheckBoxList()
    var checkBoxListBean4 = CheckBoxList()
    var checkBoxListBean5 = CheckBoxList()
    var materialList = ArrayList<MaterialListBean>()
    var handler: Handler = object : Handler() {
        @SuppressLint("HandlerLeak")
        override fun handleMessage(msg: Message) {
            when(msg.what) {
                0x10 -> {
                    var s: String = msg.obj as String
                    val intent = Intent()
                    intent.putExtra("type", "Error")
                    intent.putExtra("error", s)
                    val clazz = Class.forName("com.glory.cqaospda.view.SkipDialogActivity")
                    intent.setClass(this@QueryMaterialReplaceActivity, clazz)
                    startActivity(intent)
                }
            }
            super.handleMessage(msg)
        }
    }
    var listQty = arrayListOf(
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        "9",
        "10",
        "11",
        "12",
        "13",
        "14",
        "15",
        "16",
        "17",
        "18",
        "19",
        "20"
    )


    override fun initData() {
        cbMaintainVerification0.isChecked = true
        queryEqpData(etEqpId)

        viewModel.defUI.callObserve.observe(this@QueryMaterialReplaceActivity) {
            if (!Constant.okgoError) {
                when (it.type) {
                    1 -> {
                        Constant.eqpMaterialsBean = it.item as EqpMaterialsBean
                        materialsData()

                    }
                    2 -> {
                        list.clear()
                        val baseConfigBean = it.item as BaseConfigBean
                        for (item in baseConfigBean.mItemList) {
                            list.add(item.mItemValue)
                        }
                        if (eqpid == "") {
                            eqpid = etEqpId.text.toString()
                        }
                        val intent = Intent()
                        intent.putExtra("type", "materialReplace")
                        intent.putExtra("type1", "tvCarrierband")
                        intent.putExtra("eqpid", eqpid)
                        intent.putExtra("TypeList", list)
                        intent.putExtra("BuyOff", BuyOff)
                        intent.putExtra("Remark", etRemark.text.toString())
                        val clazz = Class.forName("com.glory.cqaospda.view.SkipDialogActivity")
                        intent.setClass(this, clazz)
                        startActivityForResult(intent, 1)
                    }
                    3 -> {

                    }
                    4 -> {
                        if (eqpid == "") {
                            eqpid = etEqpId.text.toString()
                        }
                        viewModel.defaultEqpMaterials(eqpid)
                        materialList.clear()
                        viewModel.defUI.toastEvent.value = ToastMessageBean("物料更换成功", true)
                        if (typeActivity == "Startjob2") {
                            finish()
                        } else {
                            intent.setClass(this, HomeActivity::class.java)
                            startActivity(intent)
                            finish()
                        }
                        finish()
                    }
                }
            }else{
                Constant.okgoError = false
            }
        }

        ivTypeArrow.setOnClickListener {
            if (lineMaterial.visibility == View.GONE) {
                ivTypeArrow.setImageResource(R.drawable.down)
                lineMaterial.visibility = View.VISIBLE
            } else {
                ivTypeArrow.setImageResource(R.drawable.left)
                lineMaterial.visibility = View.GONE
            }
        }

        tvSubmin.setOnClickListener {
            if(etEqpId.text.toString() == ""){
                viewModel.defUI.toastEvent.value = ToastMessageBean("请扫描设备ID", true)
                return@setOnClickListener
            }

            if (Constant.isFastClick()) {
                if (materialList.size <= 0) {
                    viewModel.defUI.toastEvent.value = ToastMessageBean("请更换物料信息", true)
                    return@setOnClickListener
                }
                checkBoxListBean1.maintenanceKey = "0"
                checkBoxListBean1.maintenanceValue = tvBuyoffType.text.toString()
                checkBoxList.add(checkBoxListBean1)
//                if (BuyOff == "0") {
                    viewModel.defaultEquipmentConversion(
                        materialList,
                        "",
                        checkBoxList,
                        etEqpId.text.toString(),
                        etRemark.text.toString(),
                        BuyOff,
                        etKeifeTemp.text.toString())
//                } else {
//                    if (etRemark.text.toString() == "") {
//                        viewModel.defUI.toastEvent.value = ToastMessageBean("请描述信息", true)
//                    } else {
//                        viewModel.defaultEquipmentConversion(
//                            materialList, checkBoxList,
//                            etEqpId.text.toString(), etRemark.text.toString(),
//                            BuyOff, etKeifeTemp.text.toString()
//                        )
//                    }
//                }
            }
        }

        etKeifeTemp.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun afterTextChanged(editable: Editable?) {
                var s = editable.toString()
                if (s == "."){
                    etKeifeTemp.setText("")
                    return
                }
//                if(s.length > 2){
//                    if (s.substring(0,1) == "0"){
//                        val drop = s.drop(1)
//                        s = drop
//                        etKeifeTemp.setText(drop)
//                    }
//                }
                val mEditable = if (s == "")0f else s.toFloat()
                if (mEditable < 0){
                    etKeifeTemp.setText("")
                }
                if (mEditable > 1000){
                    etKeifeTemp.setText("1000")
                }

            }
        })

        flBuyoffType.setOnClickListener {
            codePop = PopWindowsUtils.getOneChoosePop(this, flBuyoffType.width, listQty,
                ivBuyoffTypeArrow, object : PopWindowsUtils.PopTextAndPositionCallback {
                    override fun onSuccess(string: String, potion: Int) {
                        tvBuyoffType.text = string
                        checkBoxListBean1.maintenanceValue = tvBuyoffType.text.toString()
                    }
                }
            )
            if (codePop!!.isShowing) {
                codePop?.dismiss()
            } else {
                PopWindowsUtils.setArrowShow(ivBuyoffTypeArrow)
                codePop?.showAsDropDown(flBuyoffType, 0, 0)
            }
        }
        flQuanType.setOnClickListener {
            codePop = PopWindowsUtils.getOneChoosePop(this, flQuanType.width, listQty,
                ivQuanTypeArrow, object : PopWindowsUtils.PopTextAndPositionCallback {
                    override fun onSuccess(string: String, potion: Int) {
                        tvQuanType.text = string
                        checkBoxListBean2.maintenanceValue = tvQuanType.text.toString()
                    }
                }
            )
            if (codePop!!.isShowing) {
                codePop?.dismiss()
            } else {
                PopWindowsUtils.setArrowShow(ivQuanTypeArrow)
                codePop?.showAsDropDown(flQuanType, 0, 0)
            }
        }
        flQAType.setOnClickListener {
            codePop = PopWindowsUtils.getOneChoosePop(this, flQAType.width, listQty,
                ivQATypeArrow, object : PopWindowsUtils.PopTextAndPositionCallback {
                    override fun onSuccess(string: String, potion: Int) {
                        tvQAType.text = string
                        checkBoxListBean3.maintenanceValue = tvQAType.text.toString()
                    }
                }
            )
            if (codePop!!.isShowing) {
                codePop?.dismiss()
            } else {
                PopWindowsUtils.setArrowShow(ivQATypeArrow)
                codePop?.showAsDropDown(flQAType, 0, 0)
            }
        }
        flpeelingType.setOnClickListener {
            codePop = PopWindowsUtils.getOneChoosePop(this, flpeelingType.width, listQty,
                ivpeelingTypeArrow, object : PopWindowsUtils.PopTextAndPositionCallback {
                    override fun onSuccess(string: String, potion: Int) {
                        tvpeelingType.text = string
                        checkBoxListBean4.maintenanceValue = tvpeelingType.text.toString()
                    }
                }
            )
            if (codePop!!.isShowing) {
                codePop?.dismiss()
            } else {
                PopWindowsUtils.setArrowShow(ivpeelingTypeArrow)
                codePop?.showAsDropDown(flpeelingType, 0, 0)
            }
        }
        flbinType.setOnClickListener {
            codePop = PopWindowsUtils.getOneChoosePop(this, flbinType.width, listQty,
                ivbinTypeArrow, object : PopWindowsUtils.PopTextAndPositionCallback {
                    override fun onSuccess(string: String, potion: Int) {
                        tvbinType.text = string
                        checkBoxListBean5.maintenanceValue = tvbinType.text.toString()
                    }
                }
            )
            if (codePop!!.isShowing) {
                codePop?.dismiss()
            } else {
                PopWindowsUtils.setArrowShow(ivbinTypeArrow)
                codePop?.showAsDropDown(flbinType, 0, 0)
            }
        }

    }

    private fun materialsData() {
        val carriertapeData = filteringData("carriertape")
        initRecyclerView(rvCarrierList, this)
        val carriertapeAdapter = MateriaAdapter(carriertapeData, "carriertapeData")
        rvCarrierList.setAdapter(carriertapeAdapter)
        carriertapeAdapter.setOnItemClickListener {data ->
            intent.putExtra("type", "materiaAdapter")
            intent.putExtra("materiaData", data)
            intent.setClass(this, SkipDialogActivity::class.java)
            startActivity(intent)
        }

        val reelData = filteringData("reel")
        initRecyclerView(rvReelList, this)
        val reelDataAdapter = MateriaAdapter(reelData, "reelData")
        rvReelList.setAdapter(reelDataAdapter)
        reelDataAdapter.setOnItemClickListener {data ->
            intent.putExtra("type", "materiaAdapter")
            intent.putExtra("materiaData", data)
            intent.setClass(this, SkipDialogActivity::class.java)
            startActivity(intent)
        }

        val coverData = filteringData("cover")
        initRecyclerView(rvCoverList, this)
        val coverDataAdapter = MateriaAdapter(coverData, "coverData")
        rvCoverList.setAdapter(coverDataAdapter)
        coverDataAdapter.setOnItemClickListener {data ->
            intent.putExtra("type", "materiaAdapter")
            intent.putExtra("materiaData", data)
            intent.setClass(this, SkipDialogActivity::class.java)
            startActivity(intent)
        }

        val plugData = filteringData("plug")
        initRecyclerView(rvPlugList, this)
        val plugDataAdapter = MateriaAdapter(plugData, "plugData")
        rvPlugList.setAdapter(plugDataAdapter)
        plugDataAdapter.setOnItemClickListener {data ->
            intent.putExtra("type", "materiaAdapter")
            intent.putExtra("materiaData", data)
            intent.setClass(this, SkipDialogActivity::class.java)
            startActivity(intent)
        }

    }

    override fun initView(savedInstanceState: Bundle?) {
        FreeApi_ActivityManager.getActivityManager().addActivity(this)
        tvBaseSubmit.visibility = View.GONE
        llLot.visibility = View.GONE
        tvTitle.text = "材料更换"
        cbMaintainVerification0.isEnabled = false
        val instance = MyApp.instance
        instance!!.handler = handler
        tvUserName.text = Constant.UserName
        var showPlugin = intent.getStringExtra("showPlugin")
        if (showPlugin.equals("materialreplace")) {
            tvTitle.text = "物料信息查询"
            tvCarrierband.visibility = View.GONE
            tvReel.visibility = View.GONE
            tvMaterialpipe.visibility = View.GONE
            tvCoverbelt.visibility = View.GONE
            llRepair.visibility = View.GONE
            llKeifeTemp.visibility = View.GONE
            llRemark.visibility = View.GONE
            tvSubmin.visibility = View.GONE
        }
        var type = intent.getStringExtra("type")
        typeActivity = intent.getStringExtra("TypeActivity").toString()

        var eqpid = intent.getStringExtra("eqpID")

        if (eqpid != null && eqpid != "") {
            etEqpId.setText(eqpid)
            viewModel.defaultEqpMaterials(eqpid)
        }
        if ("fragment" == type) {
            line1.visibility = View.GONE
            line2.visibility = View.GONE
            line3.visibility = View.GONE
            line4.visibility = View.GONE
        }

        cbMaintainVerification0.setOnClickListener(this)
        cbMaintainVerification1.setOnClickListener(this)
        cbMaintainVerification2.setOnClickListener(this)
        cbMaintainVerification3.setOnClickListener(this)
        cbMaintainVerification4.setOnClickListener(this)

        tvCarrierband.setOnClickListener {
            if (Constant.isFastClick()) {
                viewModel.defaultGetBaseConfig()
            }
        }
//        tvCoverbelt.setOnClickListener {
//            if (Constant.isFastClick()) {
//                viewModel.defaultGetBaseConfig()
//            }
//        }
//        tvReel.setOnClickListener {
//            if (Constant.isFastClick()) {
//                viewModel.defaultGetBaseConfig()
//            }
//        }
//        tvMaterialpipe.setOnClickListener {
//            if (Constant.isFastClick()) {
//                viewModel.defaultGetBaseConfig()
//            }
//        }
    }

    override fun layoutId(): Int {
        return R.layout.activity_material_replace
    }

    private fun queryEqpData(
        editText: FreeUI_ClearEditText?,
    ) {
        EditTextEnterUtils.initEnterToUpperCase(editText)
        FreeApi_EditTextUtils.setEditTextListener(editText, this) { s: String? ->
            eqpid = s!!
            Constant.eqpMaterialsBean = null
            materialsData()
            viewModel.defaultEqpMaterials(s)
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == 520) {
            try {
                val view = window.decorView.findFocus() as EditText
                when (view) {
                    etEqpId -> {
                        etEqpId.setText("")
                    }
                }
            } catch (e: Exception){
                println(e.message)
            }
        }
        return super.onKeyDown(keyCode, event)
    }

    private fun filteringData(type: String): List<Materialslist?> {
        val mEntity: MutableList<Materialslist?> = ArrayList()
        when (type) {
            "carriertape" -> {

                if (Constant.eqpMaterialsBean != null && Constant.eqpMaterialsBean!!.mMaterialslist != null) {
                    for (s in Constant.eqpMaterialsBean!!.mMaterialslist!!) {
                        if (s!!.mMaterialId != null && s!!.mMaterialId!!.length > 3) {
                            val substring = s!!.mMaterialId!!.substring(0, 3)
                            val substring2 = s.mMaterialId!!.substring(0, 2)
                            if (substring.equals("A04") || substring2.equals("04")) {
                                mEntity.add(s)
                            }
                        }
                    }
                }
                if (materialList.size > 0) {
                    for (material in materialList) {
                        if (material.materialId.subSequence(0, 3).equals("A04") ||
                            material.materialId.subSequence(0, 2).equals("04")
                        ) {
                            val materialslist = Materialslist(
                                material.materialCode,
                                material.materialId,
                                material.materialQty,
                                material.materialType,
                                material.materialUnit,
                                material.vendorCode,
                                material.materialCode,
                                material.materialUniqueCode,
                                true
                            )
                            mEntity.clear()
                            mEntity.add(materialslist)
                        }
                    }
                }
            }
            "reel" -> {
                if (Constant.eqpMaterialsBean != null && Constant.eqpMaterialsBean!!.mMaterialslist != null) {
                    for (s in Constant.eqpMaterialsBean!!.mMaterialslist!!) {
                        if (s!!.mMaterialId != null && s!!.mMaterialId!!.length > 3) {
                            val substring = s!!.mMaterialId!!.substring(0, 3)
                            val substring2 = s.mMaterialId!!.substring(0, 2)
                            if (substring.equals("A06") || substring2.equals("06")) {
                                mEntity.add(s)
                            }
                        }
                    }
                }
                if (materialList.size > 0) {
                    for (material in materialList) {
                        if (material.materialId.subSequence(0, 3).equals("A06") ||
                            material.materialId.subSequence(0, 2).equals("06")
                        ) {
                            val materialslist = Materialslist(
                                material.materialCode,
                                material.materialId,
                                material.materialQty,
                                material.materialType,
                                material.materialUnit,
                                material.vendorCode,
                                material.materialCode,
                                material.materialUniqueCode,
                                true
                            )
                            mEntity.clear()
                            mEntity.add(materialslist)
                        }
                    }
                }
            }
            "cover" -> {
                if (Constant.eqpMaterialsBean != null && Constant.eqpMaterialsBean!!.mMaterialslist != null) {
                    for (s in Constant.eqpMaterialsBean!!.mMaterialslist!!) {
                        if (s!!.mMaterialId != null && s!!.mMaterialId!!.length > 3) {
                            val substring = s!!.mMaterialId!!.substring(0, 5)
                            val substring2 = s.mMaterialId!!.substring(0, 4)
                            if (substring.equals("A0500") || substring2.equals("0500")) {
                                mEntity.add(s)
                            }
                        }
                    }
                }
                if (materialList.size > 0) {
                    for (material in materialList) {
                        if (material.materialId.subSequence(0, 5).equals("A0500") ||
                            material.materialId.subSequence(0, 4).equals("0500")
                        ) {
                            val materialslist = Materialslist(
                                material.materialCode,
                                material.materialId,
                                material.materialQty,
                                material.materialType,
                                material.materialUnit,
                                material.vendorCode,
                                material.materialCode,
                                material.materialUniqueCode,
                                true
                            )
                            mEntity.clear()
                            mEntity.add(materialslist)
                        }
                    }
                }
            }
            "plug" -> {
                if (Constant.eqpMaterialsBean != null && Constant.eqpMaterialsBean!!.mMaterialslist != null) {
                    for (s in Constant.eqpMaterialsBean!!.mMaterialslist!!) {
                        if (s!!.mMaterialId != null && s!!.mMaterialId!!.length > 3) {
                            val substring = s!!.mMaterialId!!.substring(3, 5)
                            val ss = s.mMaterialId!!.substring(0, 3)
                            val substring2 = s.mMaterialId!!.substring(2, 4)
                            val ss2 = s.mMaterialId!!.substring(0, 2)
                            if ((ss == "A05" && substring != "00") || (ss2 == "05" && substring2 != "00")) {
                                mEntity.add(s)
                            }
                        }
                    }
                }
                if (materialList.size > 0) {
                    for (material in materialList) {
                        if ((material.materialId.subSequence(
                                0,
                                3
                            ) == "A05" && material.materialId.subSequence(3, 5) != "00")
                            || (material.materialId.subSequence(
                                0,
                                2
                            ) == "05" && material.materialId.subSequence(2, 4) != "00")
                        ) {
                            val materialslist = Materialslist(
                                material.materialCode,
                                material.materialId,
                                material.materialQty,
                                material.materialType,
                                material.materialUnit,
                                material.vendorCode,
                                material.materialCode,
                                material.materialUniqueCode,
                                true
                            )
                            mEntity.clear()
                            mEntity.add(materialslist)
                        }
                    }
                }
            }

        }
        return mEntity
    }

    protected fun initRecyclerView(recyclerView: RecyclerView, context: Context?) {
        recyclerView.layoutManager = LinearLayoutManager(context)
        recyclerView.itemAnimator = DefaultItemAnimator()
        recyclerView.addItemDecoration(DividerItemDecoration(context, 1))
    }

    @SuppressLint("SetTextI18n")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == 1) {
            when (resultCode) {
                1 -> {
                    val extras = data!!.getExtras()
                    val material = extras!!.getSerializable("material") as MaterialListBean
                    material.isReplace = true
                    materialList.add(material)
                    materialsData()
//                    val intent = Intent()
//                    intent.putExtra("type", "temperature")
//                    intent.setClass(this, SkipDialogActivity::class.java)
//                    startActivityForResult(intent,1)
                }
                2 -> {
                    val extras = data!!.getExtras()
                    temperature = extras!!.getString("temperature").toString()
                }

                108 -> {
                    finish()
                }
            }
        }
    }

    override fun onClick(view: View?) {
        when (view!!.id) {
//            R.id.cbMaintainVerification0 -> {
//                if (cbMaintainVerification0.isChecked) {
//                    flBuyoffType.visibility = View.VISIBLE
//                    checkBoxListBean1.maintenanceKey = "0"
//                    checkBoxListBean1.maintenanceValue = tvBuyoffType.text.toString()
//                    checkBoxList.add(checkBoxListBean1)
//                } else {
//                    flBuyoffType.visibility = View.GONE
//                    checkBoxList.remove(checkBoxListBean1)
//                }
//            }
            R.id.cbMaintainVerification1 -> {
                if (cbMaintainVerification1.isChecked) {
                    flQuanType.visibility = View.VISIBLE
                    checkBoxListBean2.maintenanceKey = "1"
                    checkBoxListBean2.maintenanceValue = tvQuanType.text.toString()
                    checkBoxList.add(checkBoxListBean2)
                } else {
                    flQuanType.visibility = View.GONE
                    checkBoxList.remove(checkBoxListBean2)
                }
            }
            R.id.cbMaintainVerification2 -> {
                if (cbMaintainVerification2.isChecked) {
                    flQAType.visibility = View.VISIBLE
                    checkBoxListBean3.maintenanceKey = "2"
                    checkBoxListBean3.maintenanceValue = tvQAType.text.toString()
                    checkBoxList.add(checkBoxListBean3)
                } else {
                    flQAType.visibility = View.GONE
                    checkBoxList.remove(checkBoxListBean3)
                }
            }
            R.id.cbMaintainVerification3 -> {
                if (cbMaintainVerification3.isChecked) {
                    flpeelingType.visibility = View.VISIBLE
                    checkBoxListBean4.maintenanceKey = "3"
                    checkBoxListBean4.maintenanceValue = tvpeelingType.text.toString()
                    checkBoxList.add(checkBoxListBean4)
                } else {
                    flpeelingType.visibility = View.GONE
                    checkBoxList.remove(checkBoxListBean4)
                }
            }
            R.id.cbMaintainVerification4 -> {
                if (cbMaintainVerification4.isChecked) {
                    flbinType.visibility = View.VISIBLE
                    checkBoxListBean5.maintenanceKey = "4"
                    checkBoxListBean5.maintenanceValue = tvbinType.text.toString()
                    checkBoxList.add(checkBoxListBean5)
                } else {
                    flbinType.visibility = View.GONE
                    checkBoxList.remove(checkBoxListBean5)
                }
            }
        }
    }

    override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            intent.putExtra("type", "KeyEvent")
            intent.setClass(this, SkipDialogActivity::class.java)
            startActivityForResult(intent, 1)
            return false
        }
        return super.onKeyUp(keyCode, event)
    }
}